<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::group([
    'namespace' => '\App\\Http\\Controllers\\api',
    'middleware' => 'logaccess',//请求日志中间件
], function (\Illuminate\Routing\Router $router) {
    Route::POST('/xiaozhuanbang', [\App\Http\Controllers\api\AppController::class, 'xiaozhuanbang']);//小转帮回调
    Route::get('/xianwan', [\App\Http\Controllers\api\AppController::class, 'xianwan']);//闲玩回调
    Route::any('/Commission', [\App\Http\Controllers\api\AppController::class, 'Commission']);//分销测试
    Route::get('/notice', [\App\Http\Controllers\api\AppController::class, 'notice']);//公告
    Route::get('/withdrawalinfo', [\App\Http\Controllers\api\AppController::class, 'withdrawalinfo']);//公告
    Route::any('/upload', [\App\Http\Controllers\FileController::class, 'handle']);
    $router->group([
        'middleware' => [
            'decrypt',
            // 'encrypt',
        ],
    ], function (\Illuminate\Routing\Router $router) {
        $router->group(['prefix' => 'settings'], function () {
            Route::get('/', [\App\Http\Controllers\api\SettingController::class, 'index']);//app设置
        });

        $router->group(['prefix' => 'adtypes'], function () {
            Route::get('/list', [\App\Http\Controllers\api\AdtypeController::class, 'list']);//广告类型
        });

        $router->group(['prefix' => 'admodel'], function () {
            Route::get('/configs', [\App\Http\Controllers\api\AdmodelController::class, 'configs']);//广告配置
        });

        $router->group([
            'middleware' => 'version'
        ], function (\Illuminate\Routing\Router $router) {
            Route::prefix('oauth')->group(function () {
                Route::post('login', [\App\Http\Controllers\api\OAuthController::class, 'login']);//登录
            });

            $router->group([
                'prefix' => 'auth',
            ], function () {
                Route::post('login', 'AuthController@login');//账号密码登录
                Route::group([
                    'middleware' => 'jwt',
                ], function () {
                    Route::post('logout', [\App\Http\Controllers\api\AuthController::class, 'login']);//登出
                    Route::post('refresh', [\App\Http\Controllers\api\AuthController::class, 'refresh']);//刷新token
                    Route::get('userinfo', [\App\Http\Controllers\api\AuthController::class, 'userinfo']);//用户信息+今日数据
                    Route::get('groupInfo', [\App\Http\Controllers\api\AuthController::class, 'groupInfo']);//用户组信息

                });
            });

            $router->group(['prefix' => 'app'], function () {
                Route::get('/list', [\App\Http\Controllers\api\AppController::class, 'list']);//app列表

            });

            $router->group(['prefix' => 'adrewards', 'middleware' => ['jwt',
                //'apithrottle:3,1'
            ]], function () {
                Route::post('/', [\App\Http\Controllers\api\AdrewardController::class, 'create']);//广告奖励
                Route::post('/receive', [\App\Http\Controllers\api\AdrewardController::class, 'receive']);//广告奖励领取
            });

            $router->group(['prefix' => 'wallet', 'middleware' => 'jwt',], function () {
                Route::get('/incomes', [\App\Http\Controllers\api\UserWalletController::class, 'incomes']);//收入明细
                Route::get('/outcomes', [\App\Http\Controllers\api\UserWalletController::class, 'outcomes']); //支出明细
            });

            $router->group(['prefix' => 'withdrawal', 'middleware' => 'jwt',], function () {
                Route::post('/apply', [\App\Http\Controllers\api\UserWithdrawController::class, 'apply']);//提现申请
            });

            $router->group(['prefix' => 'user', 'middleware' => 'jwt',], function () {
                Route::get('/invite-code', [\App\Http\Controllers\api\UserController::class, 'inviteCode']);//邀请码
                Route::get('/group-code', [\App\Http\Controllers\api\UserController::class, 'groupCode']);//邀请码
                Route::get('/earnings', [\App\Http\Controllers\api\UserController::class, 'earnings']);//账单

                Route::get('team', [\App\Http\Controllers\api\UserController::class, 'team']);//团队
                Route::get('income', [\App\Http\Controllers\api\UserController::class, 'income']);//用户收入明细
                Route::post('upload', [\App\Http\Controllers\api\UserController::class, 'upload']);//文件上传
                Route::post('userinfoupdate', [\App\Http\Controllers\api\UserController::class, 'userinfoupdate']);//文件上传

            });

            $router->group(['prefix' => 'group', 'middleware' => 'jwt',], function () {
                Route::post('/prepay', [\App\Http\Controllers\api\PaymentWechatController::class, 'prepay']);//申请团长
                Route::post('/paycheck', [\App\Http\Controllers\api\PaymentWechatController::class, 'paycheck']);//团长订单
            });


            $router->group(['prefix' => 'popularize', 'middleware' => 'jwt',], function () {
                Route::get('/summary', [\App\Http\Controllers\api\PopularizeController::class, 'summary']);//团长概况
                Route::get('/disciples', [\App\Http\Controllers\api\PopularizeController::class, 'disciples']);//团长概况
                Route::get('/purse', [\App\Http\Controllers\api\PopularizeController::class, 'purse']);//
                Route::get('/commissions', [\App\Http\Controllers\api\PopularizeController::class, 'commissions']);//佣金明细
                Route::get('/bills', [\App\Http\Controllers\api\PopularizeController::class, 'bills']);//账单明细
                Route::get('/invites', [\App\Http\Controllers\api\PopularizeController::class, 'invites']);//收入明细
            });
        });
    });

    $router->group(['prefix' => 'system',], function () {
        Route::get('get_account_balance', [\App\Http\Controllers\api\SystemController::class, 'get_account_balance']);
        Route::post('set_account_balance', [\App\Http\Controllers\api\SystemController::class, 'set_account_balance']);
        Route::post('get_charge_history', [\App\Http\Controllers\api\SystemController::class, 'get_charge_history']);
    });

    // 订单接口 (第三方调用，不需要JWT认证)
    $router->group(['prefix' => 'orders'], function () {
        Route::post('/receive', [\App\Http\Controllers\api\OrderController::class, 'receive']);
        Route::get('/status', [\App\Http\Controllers\api\OrderController::class, 'status']);
    });

    // 奖励回调接口 (第三方调用，不需要JWT认证)
    $router->group(['prefix' => 'award'], function () {
        Route::get('/callback', [\App\Http\Controllers\api\AwardController::class, 'callback']);
    });
    // 赏帮玩任务回调接口 (第三方调用，不需要JWT认证)
    $router->group(['prefix' => 'task'], function () {
        Route::post('/callback', [\App\Http\Controllers\api\TaskCallbackController::class, 'callback']);
    });
    // 企鹅订单回调接口 (第三方调用，不需要JWT认证)
    $router->group(['prefix' => 'order'], function () {
        Route::post('/callback', [\App\Http\Controllers\api\OrderCallbackController::class, 'callback']);
    });
});
